package logic

import (
	"context"
	"month/model/redis"

	"month/userrpc/internal/svc"
	"month/userrpc/userrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductRankLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProductRankLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductRankLogic {
	return &ProductRankLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProductRankLogic) ProductRank(in *userrpc.ProductRankRequest) (*userrpc.ProductRankResponse, error) {
	// todo: add your logic here and delete this line
	scores := redis.Rdb.ZRevRangeWithScores("productRank", 0, 9)
	var sli []*userrpc.ProductRank
	for _, z := range scores.Val() {
		one := userrpc.ProductRank{
			Like: int64(z.Score),
			Name: z.Member.(string),
		}
		sli = append(sli, &one)
	}
	return &userrpc.ProductRankResponse{Rank: sli}, nil
}
